{{define "official-account.setting"}}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>公众号配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/statics/third-pkg/layui/css/layui.css">
    <link rel="stylesheet" href="/statics/admin/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }

        .layui-form-radio {
            display: block;
        }
    </style>
</head>

<body>
<div class="layui-form layuimini-form">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>微信公众号</legend>
    </fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label">公众号名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" value="{{ .setting.Name }}" class="layui-input">
        </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>公众号开发者信息</legend>
    </fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label required">AppID</label>
        <div class="layui-input-block">
            <input type="password" name="app_id" lay-verify="required" lay-reqtext="appid不能为空" placeholder="请输入appid" value="{{ .setting.AppID }}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">AppSecret</label>
        <div class="layui-input-block">
            <input type="password" name="app_secret" lay-verify="required" lay-reqtext="AppSecret不能为空" placeholder="请输入AppSecret" value="{{ .setting.AppSecret }}" class="layui-input">
        </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>服务器配置</legend>
    </fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label">URL</label>
        <div class="layui-input-block">
            <input type="password" name="url"  value="" class="layui-input layui-disabled" disabled>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">Token</label>
        <div class="layui-input-block">
            <input type="password" name="token" value="{{ .setting.Token }}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">EncodingAESKey</label>
        <div class="layui-input-block">
            <input type="password" name="encoding_aes_key"  placeholder="请输入EncodingAESKey" value="{{ .setting.EncodingAESKey }}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">消息加密方式</label>
        <div class="layui-input-block">
            <input type="radio" name="encryption_type"  value="1" title=" 明文模式 (不使用消息体加解密功能，安全系数较低) " {{if  eq .setting.EncryptionType 1}} checked="" {{end}}>
            <input type="radio" name="encryption_type" value="2" title=" 兼容模式 (明文、密文将共存，方便开发者调试和维护) " {{if eq .setting.EncryptionType 2}} checked="" {{end}}>
            <input type="radio" name="encryption_type" value="3" title="  安全模式（推荐） (消息包为纯密文，需要开发者加密和解密，安全系数高)  " {{if eq .setting.EncryptionType 3}} checked="" {{end}}>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/statics/third-pkg/layui/layui.js"></script>
<script src="/statics/admin/js/lay-config.js?v=2.0" charset="utf-8"></script>
<script>

    layui.use(['form','request','layer','miniTab',"common",'fileManager','upload'], function() {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            $=layui.$,
            common=layui.common,
            fileManager = layui.fileManager
            ,upload = layui.upload,
            request=layui.request;
        fileManager.render({
            elem: '#fileManager'
            , method:'post'
            , id: 'fmTest'
            , btn_upload: true
            , btn_create: true
            , url: 'data.php?action=get_file_data'
            , thumb: {'nopic':'/filemanage/upload/null-100x100.jpg','width':100,'height':100}
            , parseData: function (res) {
                /*
                data:[{
                    thumb:文件地址用于显示
                    ,type:文件类型  directory文件夹,png|gif|png|image图片,其它任意
                    ,path:文件夹路径用于打开本文件夹
                }]
                */
                let _res = [];
                _res.code = 0;
                _res.data = res.images;
                _res.count = res.count
                return _res;
            }
            , done: function (res,curr,count) {
                // console.log(res,curr,count)
            }
            , page: {limit:12}
            , where: {action: 'get_file_data'}
        });
        //监听提交
        form.on('submit(saveBtn)', function(data) {
            var subdata={
                ...data.field,
                "encryption_type":Number.parseInt(data.field['encryption_type'])
            }
            request.post('admin/official-account/setting',subdata).then(function (response) {
                if(response.data.code==0){
                    layer.msg("编辑公众号配置成功",{
                        time:1000
                    },function (){
                        window.location.href='/admin/official-account/setting';
                    })
                }else{
                    layer.msg(response.data.msg);
                }
            }).catch(function (error) {
                console.log(error)
                layer.msg('提交失败');
            });
        });

    });
</script>
</body>

</html>
{{ end }}